﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MODEL;

namespace StudentManage
{
    public partial class Frm_Work : Form
    {
        public Frm_Work()
        {
            InitializeComponent();
        }

        private void Frm_Work_Load(object sender, EventArgs e)
        {
            //加载时进行全查询
            this.dgv_Work.DataSource = BLL.WorkManage.ChaXunClass();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //查询按钮，有条件的查询
            this.dgv_Work.DataSource = BLL.WorkManage.ChaXunClassName(this.textBox1.Text);
            
        }
        private void 添加ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            //添加窗体
            Frm_WorkAdd_Update frm_WorkAdd_Update = new Frm_WorkAdd_Update(dgv_Work);
            frm_WorkAdd_Update.ShowDialog();
        }

        private void 修改ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            //修改窗体
            Frm_WorkAdd_Update frm_WorkAdd_Update = new Frm_WorkAdd_Update(dgv_Work);
            frm_WorkAdd_Update.Text = "修改考勤记录";
            frm_WorkAdd_Update.ShowDialog();
        }
        private void 删除ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {

            Work work = new Work();
            work.W_ID = int.Parse(dgv_Work.SelectedRows[0].Cells["W_ID"].Value.ToString());


            DialogResult dr = MessageBox.Show("确定要删除吗？", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            try
            {
                if (dr == DialogResult.Yes)
                {
                    //执行删除操作
                    int num = BLL.WorkManage.WorkDelete(work);

                    if (num > 0)
                    {
                        MessageBox.Show("操作成功");
                        this.dgv_Work.DataSource = BLL.WorkManage.ChaXunClass();
                        //Frm_List.listBox1.Items.Add($"删除卡号为：{dgv_Work.SelectedRows[0].Cells["W_StuCardId"].Value.ToString()} 的考勤记录，操作成功");

                    }
                    else
                    {
                        MessageBox.Show("操作失败");
                       // Frm_List.listBox1.Items.Add($"删除卡号为：{dgv_Work.SelectedRows[0].Cells["W_StuCardId"].Value.ToString()} 的考勤记录，操作失败");
                    }

                }
            }
            catch (Exception ex)
            {
                //显示错误信息
                MessageBox.Show(ex.Message);
                //Frm_List.listBox1.Items.Add("执行操作时出现问题:\t\n" + ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte[] data = new byte[12];
            if (HPITRFID.EPCSDKHelper.IdentifySingleTag(Frm_Main.handle, data, null, 0) == true)
            {
                MessageBox.Show("读取成功");
                // 将结果展示到文本框中
                this.textBox1.Text = HPITRFID.ConvertHelper.ByteArrayToHexString(data);
            }
            else
            {
                MessageBox.Show("读取失败");
            }
        }
    }
    }
